package com.jelly.config.shiro.filter;

import com.jelly.common.util.web.WebUtilsPro;
import org.apache.shiro.web.filter.AccessControlFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 自定义演示模式滤器
 */
public class TestFilter extends AccessControlFilter {

    @Override
    protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception {

        // 过滤器当前request请求 是否为ajax请求
        if (WebUtilsPro.isAjaxRequest((HttpServletRequest) servletRequest)) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            resultMap.put("status", false);
            resultMap.put("errorMsg", "演示模式禁止修改，删除，请下载项目自行玩耍！");
            WebUtilsPro.out(servletResponse, resultMap);
            return false;
        }

        return true;
    }

    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {

        return false;
    }

}